package com.dongdongshop.serviceimpl;

import com.dongdongshop.mapper.TbUserMapper;
import com.dongdongshop.pojo.TbSeller;
import com.dongdongshop.pojo.TbUser;
import com.dongdongshop.pojo.TbUserExample;
import com.dongdongshop.service.TbUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
@com.alibaba.dubbo.config.annotation.Service
public class TbUserServiceImpl implements TbUserService {
    @Autowired
    private TbUserMapper tbUserMapper;
    @Override
    public TbUser selectByTperson(String username) {
        //根据用户名查询用户信息
        TbUserExample te = new TbUserExample();
        TbUserExample.Criteria criteria = te.createCriteria();
        criteria.andUsernameEqualTo(username);
        List<TbUser> tbUsers = tbUserMapper.selectByExample(te);
        if (tbUsers.size() > 0){
            return tbUsers.get(0);
        }
        return null;
    }

    //注册用户
    @Override
    public Boolean registerInfo(TbUser tbUser) {
        try {
            int i = tbUserMapper.insertSelective(tbUser);
            if (i>0){
                return true;
            }
            return false;
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }

    //查询判断当前用户名是否存在
    @Override
    public TbUser selectByUsername(String username) {
        TbUserExample te = new TbUserExample();
        TbUserExample.Criteria criteria = te.createCriteria();
        criteria.andUsernameEqualTo(username);
        List<TbUser> tbUsers = tbUserMapper.selectByExample(te);
        if (tbUsers.size() > 0){
            return tbUsers.get(0);
        }
        return null;
    }
}
